package com.sunsharing.flow.event;

import com.sunsharing.flow.exe.ExecutionContext;
import com.sunsharing.flow.model.GraphElement;

/**
 * Created with IntelliJ IDEA.
 * User: criss
 * Date: 13-5-4
 * Time: 下午7:40
 * To change this template use File | Settings | File Templates.
 */
public abstract class WorkFlowEvent extends ApplicationEvent {

    /**事件源**/
    protected GraphElement eventSource;

    protected ExecutionContext executionContext;

    public WorkFlowEvent() {
        super();
    }


    /**
     * 功能描述:
     *     创建一个新的应用事件
     * @param source Object
     */
    public WorkFlowEvent(Object source) {
        super(source);
    }

    /**
     * 功能描述:
     *     设置事件源
     * @param eventSource long
     */
    public void setEventSource(GraphElement eventSource) {
        this.eventSource = eventSource;
    }


    public GraphElement getEventSource() {
        return this.eventSource;
    }

    public ExecutionContext getExecutionContext() {
        return executionContext;
    }

    public void setExecutionContext(ExecutionContext executionContext) {
        this.executionContext = executionContext;
    }

    /**
     * 功能描述:
     *     判断是否相等
     * @param obj Object
     * @return boolean
     */
    public boolean equals(Object obj) {

        if(obj instanceof WorkFlowEvent) {
            WorkFlowEvent o = (WorkFlowEvent)obj;
            if(o.getClass().getName().equals(this.getClass().getName()) &&
                    o.getEventSource().getId() == this.getEventSource().getId()){
                return true;
            }
        }
        return false;
    }

    /**
     * 功能描述:
     *    覆盖hashCode方法
     * @return int
     */
    public int hashCode() {
        return this.getEventSource().getId().hashCode();
    }




}